package ru.pb.game.network.protokol;

import org.apache.log4j.Logger;

import ru.pb.global.configs.DevelopConfig;
import ru.pb.global.network.engine.NioSession;
import ru.pb.global.network.engine.buffer.NioBuffer;
import ru.pb.global.network.engine.core.Protocol;
import ru.pb.global.network.utils.NetworkUtil;

public class GameProtocol implements Protocol
{
	private final Logger _log = Logger.getLogger(GameProtocol.class);

	@Override
	public NioBuffer decode(NioSession session, NioBuffer buf)
	{
		int limit = buf.limit();
		int size = buf.getUnsigned();
		int code = buf.getUnsigned();
		if(DevelopConfig.NETWORK_DEBUG)
		{
			_log.info("Принимаем байт: " + limit + " Размер пакета: " + size);
			_log.info("INFO:\n" + NetworkUtil.printData(buf));
		}
		return buf;
	}

	@Override
	public void encode(NioSession session, NioBuffer buf)
	{
		if(DevelopConfig.NETWORK_DEBUG)
		{
			_log.info("Отправляем:" + buf.limit());
			_log.info("INFO:\n" + NetworkUtil.printData(buf));
		}
	}
}